package jmu.edu.yjc.Utils;


import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtil {
    private BeanCopyUtil(){

    }
    public static <V> V copyBeans(Object source , Class<V> clazz){
        V result = null;
        //创建对象目标
        try {
            result = clazz.newInstance();
            //实现属性拷贝
            BeanUtils.copyProperties(source,result);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return result;
    }
    public static <O,V> List<V> copyBeanList(List<O> list, Class<V> clazz ){
        return list.stream()
                .map(o -> copyBeans(o, clazz))
                .collect(Collectors.toList());
    }
}
